//
//  NetworkController.h
//  TabulaImaginarius
//
//  Created by TA2 on 3/25/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <arpa/inet.h>
#import "AsyncSocket.h"
#import "AsyncUdpSocket.h"
#import "Players.h"
#import "NetworkProtocol.h"

@interface NetworkController : NSObject {
	AsyncSocket *hostingSocket;
	AsyncSocket *clientSocket;
	NSMutableArray *connectedSockets;
	NSNetService *bonjourService;
	NSNetServiceBrowser *bonjourBrowser;
	NSMutableDictionary *networkProtocols;
	UInt16 udpPort;
	BOOL hasFoundHost;
	BOOL bonjourIsActive;
	NSString *currentConnectIp;
	UInt16 currentConnectPort;
	BOOL isReconnecting;
    BOOL isReading;
    BOOL keepNetworkAlive;
}

@property (nonatomic) BOOL bonjourIsActive;
@property (nonatomic) BOOL hasFoundHost;
@property (nonatomic, readonly, retain) NSMutableDictionary *networkProtocols;

- (id)init;
- (void)startBonjourService; 
- (void)startBonjourBrowser;
- (void)sendData:(NSData *)packet toSocket:(AsyncSocket *)socket withTag:(int)tag;
- (void)sendDataToAll:(NSData *)packet withTag:(int)tag;
- (void)sendDataToAll:(NSData *)packet withTag:(int)tag butSocket:(AsyncSocket *)ignoredSocket;
- (BOOL)startSession;
- (void)keepAlive;
- (void)joinSession:(NSString *)ip port:(UInt16)port;
- (void)leaveSession;
+ (NSData *)argumentArrayToData:(NSArray *)arguments;
+ (NetworkController *)sharedNetworkController;
@end
